Repository navigation
R50-T008: Cover the failure behavior of TrieNode (Trie.js) [Data-Structures/Tree/Trie.js] - #106
Open
stavansomaiya wants to merge 1 commit into
Open
stavansomaiya wants to merge 1 commit into
stavansomaiya wants to merge 1 commit into
Conversation
This was referenced Nov 23, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
e26b07f1064Data-Structures/Tree/Trie.js→TrieNode(line 1 at the pinned commit, line 16 after this PR)5c39e87·Trie.js#L1stavansomaiya:student/e26b07f1064/R50-T008→S-AI-Projects:master(one commit on5c39e87)Summary
The Trie in
Data-Structures/Tree/Trie.jsis total: it never throws for a missing word. This PR tests its absent-result paths, which returnnull,false,0or[], instead of inventing an exception. It documents them onTrieNodeand proves the fixture inputs actually reach the named branches.Files changed
Data-Structures/Tree/Trie.jsTrieNodedescribing the absent-result paths;TrieNodeexported (no logic change)Data-Structures/Tree/test/Trie.test.jswork/R50-T008/(9 files)check.pyrunner,README.mdwrite-up,evidence.mjs,results.jsonand logs; coursework only, kept out of any upstream PRRelated Issue
Fixes: #8
This PR covers only R50-T008. Each of the 10 tasks has its own branch, commit and PR; see All 10 tasks under Additional Notes.
Type of Change
Changes Made
Data-Structures/Tree/test/Trie.test.js(new). Fixture: insert car, cat and dog.'cab'reachesfindPrefix'sreturn null // No such prefix exists(line 76), socontainsisfalse,findOccurrencesis0andfindAllWordsis[]. Prefix'ca'exists withcount === 0, so it is not a word, while'car'is (line 135). Non-string input is ignored (lines 52, 70). Failed lookups leave the trie unchanged and create no nodes, and a successfulinsert('cab')follows. Repeated insertion of'car'reuses the node, giving count 2.Data-Structures/Tree/Trie.js: JSDoc onTrieNodedescribing the absent-result paths.TrieNodeis now also exported. No logic change.work/R50-T008/:check.py,baseline.txt, andevidence.mjs, which loads an instrumented in-memory copy provingcontains('cab')hits line 76 at index 2 ('b') andfindPrefix(5)hits line 70. Plus results.Screenshots / Recordings
There is no UI, so the recording is the terminal output of a fresh run on 23 Nov 2026. The run used a clean checkout of this branch with a new
npm cifrom the lockfile. The output is copied verbatim; only the temporary checkout path is replaced by a label.Focused tests:
npx vitest run … --reporter=verbose, 7/7 passedAutomated check:
python3 work/R50-T008/check.py, exit 0Testing
Automated check:
python3 work/R50-T008/check.pyinstalls from the lockfile and runs the focused tests. It then prints input / expected / actual for every fixture row, runs each deliberate mutant in a temporary copy, and finally runs the repository test script in non-watch mode. It exits non-zero if any assertion or step fails, and records every command incommands.log.To reproduce:
Recorded results (committed in
results.json; tool versions inversions.txt):npm ci --ignore-scripts --no-audit --no-fundvitest run Data-Structures/Tree/test/Trie.test.jsnode work/R50-T008/evidence.mjscheck.pyprefix 'ca' is not a complete word, but 'car' ischeck.pymissing word 'cab' reaches the null branch of findPrefixnpm test(vitest run)npm run check-style(Prettier)codespellAcceptance criteria → evidence:
TrieNodein Data-Structures/Tree/Trie.js; every assertion has an explicit expected value.null,false,true,0,[], counts1and2, and the literal word list after the failed lookups.prefix 'ca' is not a complete word, but 'car' isinserts car, cat and dog:contains('car') === true,contains('ca') === false.repeated insertion increments the count of the same nodeinserts'car'again; the same node then has count 2.TrieNodeexported). EveryTriemethod is unchanged. The full suite passes (11977/11977).findPrefixline 76,return null // No such prefix exists. An instrumented in-memory copy provescontains('cab')hits line 76 withi = 2(missing child'b'), andfindPrefix(5)hits line 70. The other branches are named at lines 135, 142, 126 and 52.failed lookups leave the trie unchanged and later calls succeed: after the failed lookups,insert('cab')succeeds andcontains('cab') === true.Evidence files:
check.py·README.md(contract, fixture, baseline, findings) ·evidence.mjs·results.json·vitest-focused.jsonChecklist
Additional Notes
Two temporary-copy mutants are each caught by their named test: dropping
&& node.count !== 0(line 135) and returning the partial node instead ofnullat line 76. Side observation, not changed:removenever prunes nodes, becausechildrenhas no prototype. Answers are still correct; details are in the task README.Scope: the PR changes only
Data-Structures/Tree/Trie.js, its test file andwork/R50-T008/.work/R50-T008/is coursework evidence and would be removed from any later upstream PR.All 10 tasks (one PR each)
R50-T001R50-T002R50-T003R50-T004R50-T005R50-T006R50-T007R50-T008R50-T009R50-T010